package com.cheer.vo;

import cn.hutool.core.util.NumberUtil;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.experimental.Accessors;

import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * @author cheer
 */
@Data
@Accessors(chain = true)
@ApiModel("机构VO")
public class OaLearnEntryVO {

    private Integer id;

    @ApiModelProperty("机构名称")
    private String name;

    @ApiModelProperty("参与人数")
    private Integer number;

    @ApiModelProperty("参与率")
    private double rate;

    @ApiModelProperty("参与率 Str")
    private String rateStr;

    public static final Map<String, String> headerAlias = new LinkedHashMap<>();

    static{
        headerAlias.put("name","单位名称");
        headerAlias.put("rateStr","参与率");
        headerAlias.put("number","参与人数");
    }

    public static List<OaLearnEntryVO> convertToOaLearnEntryVO(List<OaLearnEntryCompareInfoVO> list) {

        List<OaLearnEntryVO> vos = list.stream().map(infoVO -> {
            OaLearnEntryVO oaLearnEntryVO = new OaLearnEntryVO();

            String[] split = infoVO.getName().split("-");
            oaLearnEntryVO.setName(split[split.length-1]);
            oaLearnEntryVO.setId(infoVO.getId());
            oaLearnEntryVO.setNumber(infoVO.getCount());
            oaLearnEntryVO.setRate(infoVO.getRate());
            oaLearnEntryVO.setRateStr((NumberUtil.round((infoVO.getRate() * 100), 2) )+"%");
            return oaLearnEntryVO;
        }).collect(Collectors.toList());
        return vos;
    }


}
